<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:insert="~{include :: header('编辑项目')}" />
	<th:block th:insert="~{include :: summernote-css}" />
	<th:block th:insert="~{include :: select2-css}" />
	<th:block th:insert="~{include :: datetimepicker-css}" />
</head>
<body>
	<div class="main-content">
        <form class="form-horizontal" id="form-projects-add" th:object="${projectsInfo}">
			<input name="id"  type="hidden"  th:field="*{id}" />
			<h4 class="form-header h4">修改项目信息</h4>
	        <div class="row">
	            <div class="col-sm-12">
	                <div class="form-group">
	                    <label class="col-sm-2 control-label is-required">项目名称</label>
	                    <div class="col-sm-8">
	                        <input name="name" id="project_name" class="form-control" type="text" th:field="*{name}" required>
	                    </div>
	                </div>
	                <div class="form-group">
	                    <label class="col-sm-2 control-label">项目描述</label>
	                    <div class="col-sm-8">
	                        <input name="description" id="description" type="hidden" th:field="*{description}">
	                        <div class="ibox-content no-padding">
	                            <div class="summernote" id="project_description"></div>
	                        </div>
	                    </div>
	                </div>
					<div class="form-group">
					    <label class="col-sm-2 control-label is-required">项目标识</label>
					    <div class="col-sm-8">
					        <input maxlength="100" name="identifier" class="form-control" id="project_identifier" type="text" th:field="*{identifier}" disabled="" required>
							<span class="help-block m-b-none">长度必须在 1 到 100 个字符之间。 仅小写字母（a-z）、数字、破折号（-）和下划线（_）可以使用。一旦保存，标识无法修改。</span>
					    </div>
					</div>
					<div class="form-group">
					    <label class="col-sm-2 control-label">项目主页</label>
					    <div class="col-sm-8">
					        <input name="homepage" class="form-control" type="text" th:field="*{homepage}">
					    </div>
					</div>
					<div class="form-group">
					    <label class="col-sm-2 control-label">负责人：</label>
					    <div class="col-sm-8">
							<select name="projectLeader" class="form-control">
							    <option value="">请选择负责人</option>
							    <option th:each="user : ${userList}" th:value="${user.userId}" th:text="${user.userName}" th:field="*{projectLeader}"></option>
							</select>
					    </div>
					</div>
					<div class="form-group">
					    <label class="col-sm-2 control-label">项目状态</label>
					    <div class="col-sm-8">
							<label class="toggle-switch switch-solid">
							    <input type="checkbox" id="state" th:field="*{state}" th:value="1">
							    <span></span>
							</label>
					    </div>
					</div>
	                <div class="hr-line-dashed"></div>
					<div class="form-group">
					    <label class="col-sm-2 control-label">客户名称</label>
					    <div class="col-sm-8">
					        <input name="customerName" class="form-control" type="text" th:field="*{customerName}">
					    </div>
					</div>
					<div class="form-group">
					    <label class="col-sm-2 control-label">网站类型</label>
					    <div class="col-sm-8">
					        <select name="operationType" class="form-control m-b" th:with="type=${@dict.getType('pro_operation_type')}">
					            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{operationType}"></option>
					        </select>
					    </div>
					</div>
					<div class="form-group">
					    <label class="col-sm-2 control-label">开发语言</label>
					    <div class="col-sm-8">
							<input type="hidden" id="project_developLanguage" th:value="*{developLanguage}" />
							<select name="developLanguage" id="developLanguage" class="form-control select2-multiple" th:with="type=${@dict.getType('pro_develop_language')}" multiple>
							    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
							</select>
					    </div>
					</div>
					<div class="form-group">
					    <label class="col-sm-2 control-label">签约日期</label>
					    <div class="col-sm-8">
							<input type="hidden" id="formattedSignDate" th:value="${@tool.dateFormate(projectsInfo.signDate)}" />
							<div class="input-group date">
							    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
							    <input type="text" class="form-control" name="signDate" id="signDate" placeholder="yyyy-MM-dd" th:field="*{signDate}">
							</div>
					    </div>
					</div>
					<div class="form-group">
					    <label class="col-sm-2 control-label">续费日期</label>
					    <div class="col-sm-8">
							<input type="hidden" id="formattedExpirDate" th:value="${@tool.dateFormate(projectsInfo.expirDate)}" />
							<div class="input-group date">
							    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
							    <input type="text" class="form-control" name="expirDate" id="expirDate" placeholder="yyyy-MM-dd" th:field="*{expirDate}">
							</div>
					    </div> 
					</div>
					<div class="form-group">
					    <label class="col-sm-2 control-label">服务器到期</label>
					    <div class="col-sm-8">
							<input type="hidden" id="formattedServerExpirDate" th:value="${@tool.dateFormate(projectsInfo.serverExpirDate)}" />
							<div class="input-group date">
							    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
							    <input type="text" class="form-control" name="serverExpirDate" id="serverExpirDate" placeholder="yyyy-MM-dd" th:field="*{serverExpirDate}">
							</div>
					    </div>
					</div>
					<div class="form-group">
					    <label class="col-sm-2 control-label">签约信息</label>
					    <div class="col-sm-8">
							<textarea id="signDetail" name="signDetail" class="form-control" th:field="*{signDetail}"></textarea>
					    </div>
					</div>
	                <div class="hr-line-dashed"></div>
					<div class="form-group">
					    <label class="col-sm-2 control-label">域名</label>
					    <div class="col-sm-8">
					        <input name="domain" class="form-control" type="text" th:field="*{domain}">
					    </div>
					</div>
					<div class="form-group">
					    <label class="col-sm-2 control-label">后台域名</label>
					    <div class="col-sm-8">
					        <input name="adminDomain" class="form-control" type="text" th:field="*{adminDomain}">
					    </div>
					</div>
					<div class="form-group">
					    <label class="col-sm-2 control-label">静态域名</label>
					    <div class="col-sm-8">
					        <input name="htmlDomain" class="form-control" type="text" th:field="*{htmlDomain}">
					    </div>
					</div>
					<div class="form-group">
					    <label class="col-sm-2 control-label">git地址</label>
					    <div class="col-sm-8">
					        <input name="gitUrl" class="form-control" type="text" th:field="*{gitUrl}">
					    </div>
					</div>
	                <div class="hr-line-dashed"></div>
					<div class="form-group">
					    <label class="col-sm-2 control-label">服务器信息</label>
					    <div class="col-sm-8">
							<textarea id="serverDetail" name="serverDetail" class="form-control" th:field="*{serverDetail}"></textarea>
					    </div>
					</div>
					<div class="form-group">
					    <label class="col-sm-2 control-label">备注</label>
					    <div class="col-sm-8">
							<textarea id="remark" name="remark" class="form-control" th:field="*{remark}"></textarea>
					    </div>
					</div>
	            </div>
	        </div>
        </form>
    </div>
	<div class="row">
		<div class="col-sm-4 col-sm-offset-2">
		    <button class="btn btn-primary" type="button" onclick="submitHandler()"><i class="fa fa-check"></i> 保 存</button>
			&emsp;
		    <button class="btn btn-danger" type="button" onclick="closeItem()"><i class="fa fa-close"></i> 取 消</button>
		</div>
	</div>

    <th:block th:insert="~{include :: footer}" />
	<th:block th:insert="~{include :: summernote-js}" />
	<th:block th:insert="~{include :: select2-js}" />
	<th:block th:insert="~{include :: datetimepicker-js}" />
	<script th:src="@{/js/assets/project_identifier.js}"></script>
    <script th:inline="javascript">
		var prefix = ctx + "project"
		$(document).ready(function () {
			var description = $("#description").val();
		    $('.summernote').summernote({
		        lang: 'zh-CN',
				height: 160
		    });
			$('#project_description').summernote('code', description);
		});
        $("#form-projects-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
				var descriptionHTML = $('#project_description').summernote('code');
				$("#description").val(descriptionHTML);

				var data = $("#form-projects-add").serializeArray();
				var state = $("input[id='state']").is(':checked') == true ? 1 : 0;
				data.push({"name": "state", "value": state});
				$.operate.saveTab(prefix + "/saveProject", data);
            }
        }
		$(function() {
			layui.use('laydate', function(){
			    var laydate = layui.laydate;
				laydate.render({ 
					elem: '#signDate',
					type: 'date'
				});
				laydate.render({ 
					elem: '#expirDate',
					type: 'date'
				});
				laydate.render({ 
					elem: '#serverExpirDate',
					type: 'date'
				});
		  	});
			
			// 设置签约日期到输入框
			// 设置日期到输入框
			var formattedSignDate = $("#formattedSignDate").val();
			if (formattedSignDate) {
				$("#signDate").val(formattedSignDate);
			}
			
			var formattedExpirDate = $("#formattedExpirDate").val();
			if (formattedExpirDate) {
				$("#expirDate").val(formattedExpirDate);
			}
			
			var formattedServerExpirDate = $("#formattedServerExpirDate").val();
			if (formattedServerExpirDate) {
				$("#serverExpirDate").val(formattedServerExpirDate);
			}
			
			// 设置开发语言到下拉框
			var developLanguage = $("#project_developLanguage").val();
			if(developLanguage && $.trim(developLanguage).length > 0){
				var languageArr = developLanguage.split(",");
				$('#developLanguage').val(languageArr).trigger("change");
			}
			
		})
    </script>
</body>
</html>
